%%

%class Scanner
%implements TokenKinds
%function nextToken
%type Token

%unicode
%line
%column

%{
    
  private Token createToken(int kind) {
    return new Token(kind,yyline+1,yycolumn+1,yytext());
  }

%}

LineTerminator                  = \r|\n|\r\n
WhiteSpace                      = {LineTerminator} | [ \t\f]
//Identifier                    = [:jletter:][:jletterdigit:][\-\_]*
Identifier                              = [a-zA-Z0-9\-\_]*

EMPTY          = E
TERMINAL       = {Identifier}
NONTERMINAL    = <{Identifier}>
ISDEFINEDAS    = ::=
OR             = \|
EOL            = \; | \.

%%

<YYINITIAL> {

<<EOF>>         {return createToken(EOF);}
{WhiteSpace}    {}
{EMPTY}         {return createToken(EMPTY);}
{TERMINAL}      {return createToken(TERMINAL);}
{NONTERMINAL}   {return createToken(NONTERMINAL);}
{ISDEFINEDAS}   {return createToken(ISDEFINEDAS);}
{OR}            {return createToken(OR);}
{EOL}           {return createToken(EOL);}

.|\n            {throw new RuntimeException(yytext()+" unmatched");}

}